//@author A0105735J
#include "CommandMark.h"

CommandMark::CommandMark(void){
	type = CommandTypeMark;
}

CommandMark::~CommandMark(void){}

void CommandMark::setID(std::vector<int> id){
	markID.clear();
	while(!id.empty()){
		markID.push_back(id.back());
		id.pop_back();
	}
}

Feedback CommandMark::execute(Receiver* receiver){
	Logger::instance()->LogMessage("trying to mark some event as done");	
	std::vector<int>::iterator iter;
	for(iter = markID.begin(); iter != markID.end(); iter++){
		Event* markEvent = receiver->getTargetEvent(*iter,1)->clone();
		undoMarkEvent.push_back(markEvent);
	}		
	return receiver->markCommand(markID, DONE);
}

Feedback CommandMark::undo(Receiver* receiver){
	Logger::instance()->LogMessage("trying to undo the marking");
	Feedback output;
	output.storeUpdateCalendar(undoMarkEvent);
	std::vector<Event*>::iterator iter;
	std::vector<int> tempID;
	for(iter = undoMarkEvent.begin(); iter != undoMarkEvent.end(); iter++){	
		std::vector<int> tempID;
		// find the event with search ID
		Event* targetEvent = receiver->getTargetEvent((*iter)->getSearchID(),2);
		// find its display ID
		tempID.push_back(targetEvent->getDisplayID());
		// mark the target event with its original status by display ID
		receiver->markCommand(tempID, (*iter)->getEventStatus());
		tempID.clear();
	}
	return output;
}